package com.weijin.model.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 统一响应结果集
 *
 * @Author WeiJin
 * @Version 1.0
 * @Date 2025/3/18 14:33
 */
@Data
@ApiModel("统一响应实体类")
public class RestResultVo<T> {
    /**
     * 状态码，0表示成功 其他表示失败
     */
    @ApiModelProperty("状态码")
    private int status;

    /**
     * 错误信息
     */
    @ApiModelProperty("错误信息")
    private String message;

    /**
     * 返回的具体内容
     */
    @ApiModelProperty("响应内容")
    private T data;

    public static <T> RestResultVo<T> success() {
        RestResultVo<T> resultVo = new RestResultVo<>();
        resultVo.setStatus(0);
        return resultVo;
    }

    public static <T> RestResultVo<T> ok(T data) {
        RestResultVo<T> resultVo = new RestResultVo<>();
        resultVo.setStatus(0);
        resultVo.setData(data);
        return resultVo;
    }

    public static <T> RestResultVo<T> ok(T data, String message) {
        RestResultVo<T> resultVo = new RestResultVo<>();
        resultVo.setStatus(0);
        resultVo.setData(data);
        resultVo.setMessage(message);
        return resultVo;
    }

    public static <T> RestResultVo<T> failed(String message) {
        RestResultVo<T> resultVo = new RestResultVo<>();
        resultVo.setStatus(-1);
        resultVo.setMessage(message);
        return resultVo;
    }


}
